package com.kpx.app.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;

import com.kpx.app.R;
import com.kpx.app.base.ActivityBase;
import com.kpx.app.bean.OrderBean;
import com.kpx.app.configs.Constants;
import com.kpx.app.http.HttpDataApi;
import com.kpx.app.http.HttpDataLoader;
import com.kpx.app.http.HttpDataReqUrl;
import com.kpx.app.http.ResObj;
import com.kpx.app.utils.MyHashMap;
import com.kpx.app.utils.UIUtils;
import com.kpx.app.utils.uiutils.ToastUtil;
import com.kpx.app.view.TitleView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by congdy on 17/4/17.
 */

public class ActivitySetWuliuInfo extends ActivityBase {
    @BindView(R.id.titleview)
    TitleView titleview;
    @BindView(R.id.et_wuliu)
    EditText etWuliu;
    @BindView(R.id.et_wuliuid)
    EditText etWuliuid;
    private OrderBean b;

    @Override
    public void initview(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_back_wuliu_info);
        ButterKnife.bind(this);
        UIUtils.setNormalTitle(titleview, "填写退货物流");
        titleview.setRight("保存", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toSave();
            }
        }, R.color.white);
    }

    private void toSave() {
        showLoadingDialog();
        MyHashMap map = new MyHashMap();//orderId(订单号)，logistics(物流公司),logisticsNum(单号)
        map.put("orderId",b.getDmId()+"");
        map.put("logistics",etWuliu.getText().toString().trim());
        map.put("logisticsNum",etWuliuid.getText().toString().trim());
        new HttpDataLoader(new HttpDataApi.OnRequestCallback() {
            @Override
            public void onRequestSuccess(String url, ResObj result, boolean isFrmCache) {
                dissmissLoadingDialog();
                if (result.getCode() == 0) {
                    finish();
                    ToastUtil.getInstance().showToast(ActivitySetWuliuInfo.this, "保存成功");
                } else {
                    ToastUtil.getInstance().showToast(ActivitySetWuliuInfo.this, result.getMsg());
                }
            }

            @Override
            public void onRequestError(String url, int statusCode, String error) {
                dissmissLoadingDialog();
                ToastUtil.getInstance().showToast(ActivitySetWuliuInfo.this, error);
            }

        }, null, null).POST(HttpDataReqUrl.URL_POST_GODDS_BACK, true, map);
    }

    @Override
    public void initData() {
        b = (OrderBean) getIntent().getExtras().getSerializable(Constants.KEY_ORDER_BEAN);
    }

    @Override
    public void onReceiver(Context context, Intent intent) {

    }

}
